package sql_query;

use Exporter;
our @ISA = qw( Exporter );
our @EXPORT = qw( %tables_conf %sqlq );


## All sql queries should be in this file.
## Access it via sql_prepare.

%tables_conf = (
	'teams'				=> 	'teams',
	'flags'				=> 	'flags',
    );

%sqlq = (
	'get_teams'			=> "SELECT thost from $tables_conf{'teams'}",
	'set_teams'			=> "INSERT into $tables_conf{'teams'} (tname,thost,tactive)  VALUES !!teams_values!!",
	'trunk_teams'			=> "TRUNCATE $tables_conf{'teams'} CASCADE",
	
	'put_flag'			=> "INSERT into $tables_conf{'flags'} (fteam,fexploit,flag) VALUES ('!!team!!','!!exploit!!','!!flag!!')",
	'get_flags'			=> "SELECT fid,flag FROM $tables_conf{'flags'} WHERE fstatus=0 ORDER BY fid DESC LIMIT 10 FOR UPDATE",
#'get_flags'			=> "SELECT fid,flag FROM $tables_conf{'flags'} ORDER BY fid DESC LIMIT 10 FOR UPDATE",
	'update_flags_fstatus'		=> "UPDATE $tables_conf{flags} SET fstatus=!!status!!,ftime_statupd=NOW() WHERE !!fids!!",
#	'update_flags_ftime_statupd'	=> "UPDATE $tables_conf{flags} SET ftime_statupd=NOW() WHERE !!fids!!",
	
	'clean_fstatus_1'		=> "UPDATE $tables_conf{flags} SET fstatus=0,ftime_statupd=NOW() WHERE (fstatus=1) AND (NOW()-ftime_statupd)>interval '2 minutes'",
    );

1;
